/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.table.alarm;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import twaver.AlarmSeverity;

public class FlashCellRenderer extends DefaultTableCellRenderer {
	
	public FlashCellRenderer(){
		setHorizontalAlignment(JLabel.CENTER);
	}
	
    public Component getTableCellRendererComponent(JTable table, Object value,
    		boolean isSelected, boolean hasFocus, int row, int column) {
    	
    	super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if(isSelected){
        	this.setBackground(table.getSelectionBackground());
        }else{
        	this.setBackground(null);
        }
        this.setText("");
        this.setToolTipText("");
    
    	if(value instanceof AlarmSeverity){
        	AlarmSeverity severity = (AlarmSeverity)value;
    		this.setText(severity.getDisplayName());
        	this.setToolTipText(severity.getDisplayName());
        	
        	if(AlarmTableDemo.isInterest(severity)){
        		if(AlarmTableDemo.flashFlag){
                	Color color = severity.getColor();
                	if(isSelected){
                		color = color.darker();
                	}
                	this.setBackground(color);
        		}
        	}else{
            	Color color = severity.getColor();
            	if(isSelected){
            		color = color.darker();
            	}
            	this.setBackground(color);
        	}
    	}

        return this;
    }
	
}